// Smith Waterman openCL kernel function.
__kernel void sw (
  __global int *matrix,  
    int tmpdim,
  __global int *subIndexes,  
  __global char *s1,
  __global char *s2)
{
  	int x = get_global_id(0);
  	int dim = tmpdim;
  	int startI = subIndexes[2*x+0];
	int startJ = subIndexes[2*x+1];

	int i = startI + 1;
	int j = startJ + 1;

	const int GAP = -1;
	int max = 0;
	int index = j+i*dim;
		
	int nw = matrix[(j-1)+(i-1)*dim] + ((s1[startJ] == s2[startI]) ? 2 : -1);
	if (nw > max) {
		max = nw;
	}

	int n = matrix[j+(i-1)*dim] + GAP;
	if (n > max) {
		max = n;
	}

	int w = matrix[(j-1)+i*dim] + GAP;
	if (w > max) {
        max = w;
	}	

	matrix[index] = max;
}




